package com.泛型;

import java.util.ArrayList;
import java.util.Comparator;

@SuppressWarnings("all")
public class GenericsExercise01 {
    public static void main(String[] args) {
        ArrayList<Employee> emp = new ArrayList<>();
        emp.add(new Employee("Jeak",18000,new MyDate(2004,11,1)));
        emp.add(new Employee("Smith",28000,new MyDate(2000,11,5)));
        emp.add(new Employee("Tom",35000,new MyDate(1998,11,3)));
        emp.add(new Employee("Jeak",18000,new MyDate(2004,11,2)));
        System.out.println(emp);

        emp.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                int n = o1.getName().compareTo(o2.getName());
                if(n != 0){
                    return n;
                }

                return o1.birthday.compareTo(o2.birthday);
            }
        });


        System.out.println(emp);
    }
}

@SuppressWarnings("all")
class Employee{
    private String name;
    private double salary;
    MyDate birthday;

    public Employee(String name, double salary, MyDate birthday) {
        this.name = name;
        this.salary = salary;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return  '\n'+name + '-' +
                "-" + salary +
                "-" + birthday;
    }
}

@SuppressWarnings("all")
class MyDate implements Comparable<MyDate>{
    private int year;
    private int month;
    private int day;
    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return year + "-" + month + "-" + day;
    }

    @Override
    public int compareTo(MyDate o) {
        if(!(o.year - year== 0))
            return o.year - year;
        if(!(o.month- month == 0))
            return o.month - month;


        return o.day - day;
    }
}